home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1997 May / EnigmA AMIGA RUN 18 (1997)(G.R. Edizioni)(IT)[!][issue 1997-05][EAR-CD II].iso / softwareupdate / system / amigados / amigadoslibrary / openfromlock.c < prev    next >
C/C++ Source or Header  |  1996-10-10  |  1KB  |  57 lines

  1. /* OpenFromLock.c   V1.0   93-03-15                */
  2. /* ROM library: "dos.library/OpenFromLock", (V36+) */
  3. /* Copyright 1993, Anders Bjerin, Amiga C Club     */
  4.  
  5. #include <dos/dos.h>
  6.  
  7. #include <clib/dos_protos.h>
  8. #include <stdio.h>
  9. #include <stdlib.h>
  10.  
  11. UBYTE *version = "$VER: OpenFromLock 1.0";
  12.  
  13. int main( int argc, char *argv[] );
  14. int main( int argc, char *argv[] )
  15. {
  16.   BPTR my_lock;
  17.   BPTR my_file;
  18.  
  19.  
  20.   /* Put an exclusive lock on an existing file: */
  21.   my_lock = Lock( "RAM:Score.dat", EXCLUSIVE_LOCK );
  22.  
  23.   /* OK? */
  24.   if( !my_lock )
  25.   {
  26.     /* Error! Could not lock the file! */
  27.     printf( "Could not put an exclusive lock on the file!\n" );
  28.     exit( 20 );
  29.   }
  30.   printf( "File exclusively locked!\n" );
  31.  
  32.   /* Open the file with help of the lock we already have: */
  33.   my_file = OpenFromLock( my_lock );
  34.   
  35.   /* OK? */
  36.   if( !my_file )
  37.   {
  38.     /* Problems! Could not open the file! */
  39.     printf( "Error! Could not open the file!\n" );
  40.     UnLock( my_lock );
  41.     exit( 21 );
  42.   }
  43.   printf( "File open!\n" );
  44.  
  45.   /* - - - */
  46.  
  47.   /* Close the file: */
  48.   Close( my_file );
  49.  
  50.   /* Unlock the file: */
  51.   UnLock( my_lock );
  52.  
  53.   printf( "File closed and unlocked!\n" );
  54.  
  55.   exit( 0 );
  56. }
  57.